package common;

import java.io.Serializable;

import javax.swing.ImageIcon;

import common.characters.CharacterInterface;

//One per player, will hold all player related information, stats etc.
public class Player implements Serializable {
	private static final long serialVersionUID = 1L;
	private final PlayerGameBoard gameBoard;
	private final PlayerGUIControl guiControl;
	private boolean isDiceRolled = false;
	private CharacterInterface character;
	private String playerName;
	private String ipNumber;
	private int strength;
	private int strengthXP = 0;
	private int craft;
	private int craftXP = 0;
	private int lives;
	private int coins;
	private String name;
	private ImageIcon image;
	private String currentCardViewed = "emptyInfoCard";
	private boolean hasDrawnCardThisTurn = false;
	private boolean hasTalisman = false;
	private int startPosition;

	public Player() {
		this.gameBoard = new PlayerGameBoard();
		this.guiControl = new PlayerGUIControl();
	}

	public void clientConnected(final String tempPlayerName,
			final CharacterInterface tempCharacter, final String IP) {
		this.character = tempCharacter;
		this.ipNumber = IP;
		this.playerName = tempPlayerName;
		this.strength = tempCharacter.getStrength();
		this.craft = tempCharacter.getCraft();
		this.lives = 4;
		this.coins = 1;
		this.name = tempPlayerName;
		this.image = tempCharacter.getImage();
		this.startPosition = tempCharacter.getStartingPosition();

	}

	public PlayerGameBoard getGameBoard() {
		return this.gameBoard;
	}

	public void diceRolled(final int i, final Game game) {
		if (!this.isDiceRolled) {
			this.guiControl.diceRolled(i);
			this.gameBoard.diceRolled(i, game.getGameTileList());
			this.isDiceRolled = true;
		}
	}

	public void tileChoosen(final Tile tile) {
		if (this.isDiceRolled) {
			this.gameBoard.tileChoosen(tile);
			this.guiControl.tileChoosen();
			this.isDiceRolled = false;
		}
	}

	public PlayerGUIControl getGUIControl() {
		return this.guiControl;
	}

	public CharacterInterface getCharacter() {
		return this.character;
	}

	public String getPlayerName() {
		return this.playerName;
	}

	public String getIpNumber() {
		return this.ipNumber;
	}

	public int getStrength() {
		return this.strength;
	}

	public void setStrength(final int i) {
		this.strength = i;
	}

	public int getStrengthXP() {
		return this.strengthXP;
	}

	public void addStrengthXP(final int i) {
		this.strengthXP = this.strengthXP + i;
		if (this.strengthXP >= 7) {
			// Game.addToLogg(getName() +
			// " has gained 1 Strength due to experience!\n");

			setStrength(getStrength() + 1);
			this.strengthXP = this.strengthXP - 7;
		}
	}

	public int getCraft() {
		return this.craft;
	}

	public void setCraft(final int i) {
		this.craft = i;
	}

	public int getCraftXP() {
		return this.craftXP;
	}

	public void addCraftXP(final int i) {
		this.craftXP = this.craftXP + i;
		if (this.craftXP >= 7) {
			// Game.addToLogg(getName() +
			// " has gained 1 Craft due to experience!\n");
			setCraft(getCraft() + 1);
			this.craftXP = this.craftXP - 7;
		}
	}

	public int getLives() {
		return this.lives;
	}

	public void setLives(final int i) {
		this.lives = i;
	}

	public int getCoins() {
		return this.coins;
	}

	public void setCoins(final int i) {
		this.coins = i;
	}

	public String getName() {
		return this.name;
	}

	public ImageIcon getImageIcon() {
		return this.image;
	}

	public String getCurrentCardViewed() {
		return ("" + this.currentCardViewed);
	}

	public void setCurrentCardViewed(final String s) {
		this.currentCardViewed = s;
	}

	public void setHasDrawnCardThisTurn(final boolean b) {
		this.hasDrawnCardThisTurn = b;
	}

	public boolean getHasDrawnCardThisTurn() {
		return this.hasDrawnCardThisTurn;
	}

	public void setTalisman(final boolean i) {
		this.hasTalisman = i;
	}

	public boolean getTalisman() {
		return this.hasTalisman;
	}

	public int getStartingPosition() {
		return this.startPosition;
	}
}
